package com.lf.lexy.dao;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.jetty.util.StringUtil;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.Table;
import com.jfinal.plugin.activerecord.TableMapping;
import com.lf.comm.MyConstants;
import com.lf.lexy.model.BlogContent;
import com.lf.lexy.webutils.CommMethod;

public class BlogContentDao extends BlogContent {
	
	
	public static final BlogContentDao me = new BlogContentDao();
	
	
	
	/**
	 * @param obj
	 */
	public void insertBlogContent(BlogContent obj){
		boolean save = obj.save();
		MyConstants.log.info("====>新增Blog结果："+save);
	}
	
	
	
	public BlogContent geetBlogContentByPK(String serialId){
		return dao.findById(serialId);
	}
	
	public  List<Record>   getBlogTypeList(String userNo){
		String sql = "SELECT t.type_no , t.type_name , COUNT(c.type_no) num FROM lexy_blog_type t  LEFT JOIN  lexy_blog_content c on  t.type_no = c.type_no WHERE t.update_user_no='"+userNo+"'  GROUP BY t.type_no";
		return Db.find(sql);
	}
	
	
	public Page<BlogContent> getBlogContentList(String userNo , String typeNo , String pageNumber , int pagesize){
		
		String select = "SELECT c.*";
		String sql = " FROM lexy_blog_type t LEFT JOIN lexy_blog_content c  ON c.type_no = t.type_no WHERE   1=1 ";
		
		if(StringUtils.isNotEmpty(userNo)){
			sql += " and c.user_no = '"+userNo+"'";
		}
		if(StringUtils.isNotEmpty(typeNo)){
			sql += " and c.type_no = '"+typeNo+"'";
		}
		
		if(StringUtils.isNotEmpty(userNo)){
			sql += " or c.show_type in ('0','1')";
		}
		if(StringUtils.isEmpty(userNo)){
			sql += " and (c.show_type in ('0') or c.show_type is null)";
		}
		
		sql += " ORDER BY c.update_time DESC";
		MyConstants.log.info("===>SQL:"+select+sql);
		return dao.paginate(Integer.parseInt(pageNumber), pagesize, select ,sql  );
	}
	
	
	
	
	
	
	
	
	
	
	
	

}
